/* ***** BEGIN LICENSE BLOCK *****
 *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is EasySNAV.
 *
 * The Initial Developer of the Original Code is
 * Antonio Gomes (tonikitoo) <tonikitoo@gmail.com>.
 * Portions created by the Initial Developer are Copyright (C) 2008
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

// FIXME: why Ci2 ?
const Ci2 = Components.interfaces;

var gSnavUtils = {

    filterKeycode : function (keyCode) {
        switch(keyCode) {
            case 0 :
            case Ci2.nsIDOMKeyEvent.DOM_VK_BACK_SPACE :  // 8
            case Ci2.nsIDOMKeyEvent.DOM_VK_TAB :         // 9
            case Ci2.nsIDOMKeyEvent.DOM_VK_RETURN :      // 13
            case Ci2.nsIDOMKeyEvent.DOM_VK_ENTER :       // 14
            case Ci2.nsIDOMKeyEvent.DOM_VK_SHIFT :       // 16
            case Ci2.nsIDOMKeyEvent.DOM_VK_CONTROL :     // 17
            case Ci2.nsIDOMKeyEvent.DOM_VK_ALT :         // 18
            case Ci2.nsIDOMKeyEvent.DOM_VK_PAUSE :       // 19
            case Ci2.nsIDOMKeyEvent.DOM_VK_CAPS_LOCK :   // 20
            case Ci2.nsIDOMKeyEvent.DOM_VK_ESCAPE :      // 27
            case Ci2.nsIDOMKeyEvent.DOM_VK_SPACE :       // 32
            case Ci2.nsIDOMKeyEvent.DOM_VK_PRINTSCREEN : // 44
            case Ci2.nsIDOMKeyEvent.DOM_VK_CONTEXT_MENU :// 93
            case Ci2.nsIDOMKeyEvent.DOM_VK_NUM_LOCK :    // 144
            case Ci2.nsIDOMKeyEvent.DOM_VK_SCROLL_LOCK : // 145
            case Ci2.nsIDOMKeyEvent.DOM_VK_META :        // 224
                return false;
        }
        return true;
    },

    filterCharCode : function(charCode) {
        switch(charCode) {
            case 0 :
            case 32: // space
            case 33: // !
            case 64: // @
            case 35: // #
            case 36: // $
            case 37: // %
            case 38: // &
            //case 42: // *
            case 40: // (
            case 41: // )
            case 95: // _
            //case 43: // +
            case 60: // <
            case 62: // >
            case 63: // ?
            case 58: // :
            case 123: // {
            case 125: // }
            case 124: // |
                return false;
        }
        return true;
    },

    keyCodeToString : function (keyCode) {
        //if (keyCode == 8) return "backspace";
        //if (keyCode == 9) return "tab";
        //if (keyCode == 13) return "enter";
        //if (keyCode == 16) return "shift";
        //if (keyCode == 17) return "ctrl";
        //if (keyCode == 18) return "alt";
        //if (keyCode == 19) return "pause/break";
        //if (keyCode == 20) return "caps lock";
        //if (keyCode == 27) return "escape";
        if (keyCode == 33) return "PageUp";
        if (keyCode == 34) return "PageDown";
        if (keyCode == 35) return "End";
        if (keyCode == 36) return "Home";
        if (keyCode == 37) return "LeftArrow";
        if (keyCode == 38) return "UpArrow";
        if (keyCode == 39) return "RightArrow";
        if (keyCode == 40) return "DownArrow";
        if (keyCode == 45) return "Insert";
        if (keyCode == 46) return "Delete";
        //if (keyCode == 91) return "LeftWindow";
        //if (keyCode == 92) return "RightWindow";
        //if(keyCode == 93) return "ContextMenu";
        //if(keyCode == 96) return "Numpad_0";
        //if(keyCode == 97) return "Numpad_1";
        //if(keyCode == 98) return "Numpad_2";
        //if(keyCode == 99) return "Numpad_3";
        //if(keyCode == 100) return "Numpad_4";
        //if(keyCode == 101) return "Numpad_5";
        //if(keyCode == 102) return "Numpad_6";
        //if(keyCode == 103) return "Numpad_7";
        //if(keyCode == 104) return "Numpad_8";
        //if(keyCode == 105) return "Numpad_9";
        //if(keyCode == 106) return "Multiply";
        //if(keyCode == 107) return "Add";
        //if(keyCode == 109) return "Subtract";
        //if(keyCode == 110) return "DecimalPoint";
        //if(keyCode == 111) return "Divide";
        if (keyCode == 112) return "F1";
        if (keyCode == 113) return "F2";
        if (keyCode == 114) return "F3";
        if (keyCode == 115) return "F4";
        if (keyCode == 116) return "F5";
        if (keyCode == 117) return "F6";
        if (keyCode == 118) return "F7";
        if (keyCode == 119) return "F8";
        if (keyCode == 120) return "F9";
        if (keyCode == 121) return "F10"
        if (keyCode == 122) return "F11"
        if (keyCode == 123) return "F12"
        //if (keyCode == 144) return "num lock";
        //if (keyCode == 145) return "scroll lock";
        //if(keyCode == 186) return ";";
        //if(keyCode == 187) return "=";
        //if(keyCode == 188) return ",";
        //if(keyCode == 189) return "-";
        //if(keyCode == 190) return ".";
        //if(keyCode == 191) return "/";
        //if(keyCode == 192) return "`";
        //if(keyCode == 219) return "[";
        //if (keyCode == 220) return "\\";
        //if(keyCode == 221) return "]";
        //if(keyCode == 222) return "'";

        return null;
    },

    charCodeToString : function (charCode) {
        if(charCode == 48) return  "0";
        if(charCode == 49) return  "1";
        if(charCode == 50) return  "2";
        if(charCode == 51) return  "3";
        if(charCode == 52) return  "4";
        if(charCode == 53) return  "5";
        if(charCode == 54) return  "6";
        if(charCode == 55) return  "7";
        if(charCode == 56) return  "8";
        if(charCode == 57) return  "9";
        if(charCode == 97) return  "a";
        if(charCode == 98) return  "b";
        if(charCode == 99) return  "c";
        if(charCode == 100) return  "d";
        if(charCode == 101) return  "e";
        if(charCode == 102) return  "f";
        if(charCode == 103) return  "g";
        if(charCode == 104) return  "h";
        if(charCode == 105) return  "i";
        if(charCode == 106) return  "j";
        if(charCode == 107) return  "k";
        if(charCode == 108) return  "l";
        if(charCode == 109) return  "m";
        if(charCode == 110) return  "n";
        if(charCode == 111) return  "o";
        if(charCode == 112) return  "p";
        if(charCode == 113) return  "q";
        if(charCode == 114) return  "r";
        if(charCode == 115) return  "s";
        if(charCode == 116) return  "t";
        if(charCode == 117) return  "u";
        if(charCode == 118) return  "v";
        if(charCode == 119) return  "w";
        if(charCode == 120) return  "x";
        if(charCode == 121) return  "y";
        if(charCode == 122) return  "z";

        return null;
    }
}
